package main

import (
	"log"
)

func main() {
	result := lengthOfLongestSubstring("abcabceb")
	log.Println(result)
}

// 找出字符串中最大不重复字符组个数
func lengthOfLongestSubstring(s string) int {
	val := []byte(s)
	kv := make([]int, 128)
	lens := len(s)
	var max, num int
	for i, j := 0, 0; i < lens && j < lens; j++ {
		if kv[val[j]] > i {
			i = kv[val[j]]
		}
		num = j - i + 1
		if num > max {
			max = num
		}
		kv[val[j]] = j + 1
	}
	return max
}
